<?php
include 'database.php'; //数据库的配置信息
require 'lianjie.php';  // 数据库的操作函数
$con = lianjieshujuku($servername, $name, $passwd);//连接数据库

$mac = $_GET['mac'];
$username = $_GET['username'];
$id = $_GET['id'];
$at = $_GET['at'];
$atname = $_GET['atname'];
$path = "floweruser/" . $username . "/" . $mac . "/" . $id . ".jpg";
//图片保存
if ($_FILES["file"]["error"] > 0) {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
    if (file_exists($path)) {
        unlink($path);
    }
    move_uploaded_file($_FILES["file"]["tmp_name"],$path);
    echo "保存在".$path;

}

//更新fname
//UPDATE `fname` SET `at` = '1|#|#|#|#|#|#|#',`atname`='狗狗花|#|#|#|#|#|#|#' WHERE `mac` = '141414141414'
if (!mysqli_select_db($con, 'flower')) {
    die("选择数据库失败");
}
$req = mysqli_query($con, "SELECT * from `fname` WHERE `mac`='$mac'");
$arry = mysqli_fetch_array($req);
$arryat = explode('|', $arry['at']);
$arryatname = explode('|', $arry['atname']);
//print_r($arryat);
//print_r($arryatname);
$arryat[$id - 1] = $at;

$arryatname[$id - 1] = $atname;
$newatnameall = "";
foreach ($arryatname as $newatname) {
    if ($newatnameall == "") {
        $newatnameall = $newatname;
    } else {
        $newatnameall = $newatnameall . "|" . $newatname;
    }
}
$newatall = "";
foreach ($arryat as $newat) {
    if ($newatall == ""){
        $newatall = $newat;
    }else{
        $newatall = $newatall."|".$newat;
    }
}
$req = mysqli_query($con, "UPDATE `fname` SET `at` = '$newatall',`atname`='$newatnameall' WHERE `mac` = '$mac'");
if($req){
    echo "成功fname";
}
echo $newatall;
echo "<br>";
echo $newatnameall;

